package windows
{
	import com.bit101.components.PushButton;
	import com.bit101.components.Window;
	import flash.events.MouseEvent;
	
	/**
	 * окно с действиями
	 * @author yaempechenki@gmail.com
	 */
	public class ActionsWindow extends Window
	{
		private var clearAll:PushButton;
		private var deleteButton:PushButton;
		private var duplicateButton:PushButton;
		
		public function ActionsWindow()
		{
			title = "Actions";
			hasMinimizeButton = true;
			width = 120;
			height = 160;
			
			duplicateButton = new PushButton(this, 10, 10, "duplicate", onDuplicateClick);
			duplicateButton.enabled = false;
			
			deleteButton = new PushButton(this, 10, 40, "delete", onDeleteClick);
			deleteButton.enabled = false;

			clearAll = new PushButton(this, 10, 70, "clear all", onClearClick);
			clearAll.enabled = false;
		}
		
		private function onDeleteClick(event:MouseEvent):void {
			if (Controller.instance.selectedObject) {
				Controller.instance.deleteObject(Controller.instance.selectedObject.id);
			}
		}
		
		private function onClearClick(event:MouseEvent):void {
			Controller.instance.clearAll();
		}    
		
		private function onDuplicateClick(event:MouseEvent):void {
			//event.stopImmediatePropagation();
			Controller.instance.duplicateItem();
		}    
		
		public function refresh():void {
			clearAll.enabled = true;
			duplicateButton.enabled = false;
			deleteButton.enabled = false;
			if (Controller.instance.selectedObject) {
				deleteButton.enabled = true;
				duplicateButton.enabled = true;
			}
		}
		
	}

}